load("//rs/tests:common.bzl", "IC_GATEWAY_RUNTIME_DEPS", "NNS_CANISTER_ENV", "NNS_CANISTER_RUNTIME_DEPS", "UNIVERSAL_CANISTER_ENV", "UNIVERSAL_CANISTER_RUNTIME_DEPS")
load("//rs/tests:system_tests.bzl", "system_test", "system_test_nns")

package(default_visibility = ["//rs:system-tests-pkg"])

exports_files([
    "secret_key.pem",
])

system_test_nns(
    name = "nns_dapp_test",
    env = {
        "IC_ICRC1_LEDGER_WASM_PATH": "$(rootpath //rs/ledger_suite/icrc1/ledger:ledger_canister)",
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "long_test",  # the P90 duration was over 6 minutes for the week starting on 2025-08-25.
    ],
    runtime_deps = IC_GATEWAY_RUNTIME_DEPS + [
        "//rs/ledger_suite/icrc1/ledger:ledger_canister",
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:libflate",
        "@crate_index//:reqwest",
        "@crate_index//:url",
    ],
)

system_test(
    name = "create_subnet_test",
    env = NNS_CANISTER_ENV | UNIVERSAL_CANISTER_ENV,
    tags = [
        "long_test",
    ],
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/nns/governance/api",
        "//rs/nns/test_utils",
        "//rs/registry/canister",
        "//rs/registry/nns_data_provider",
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/base_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test(
    name = "nns_token_balance_test",
    env = NNS_CANISTER_ENV | UNIVERSAL_CANISTER_ENV,
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/canister_client",
        "//rs/ledger_suite/common/ledger_core",
        "//rs/ledger_suite/icp:icp_ledger",
        "//rs/nervous_system/common/test_keys",
        "//rs/nns/constants",
        "//rs/nns/governance/api",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/rust_canisters/dfn_candid",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:futures",
        "@crate_index//:slog",
        "@crate_index//:tokio",
    ],
)

system_test(
    name = "nns_cycles_minting_test",
    env = NNS_CANISTER_ENV,
    tags = [
        "long_test",  # since it takes longer than 5 minutes.
    ],
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/canister_client",
        "//rs/canister_client/sender",
        "//rs/certification",
        "//rs/config",
        "//rs/crypto/tree_hash",
        "//rs/crypto/utils/threshold_sig_der",
        "//rs/ledger_suite/common/ledger_core",
        "//rs/ledger_suite/icp:icp_ledger",
        "//rs/limits",
        "//rs/nervous_system/clients",
        "//rs/nervous_system/common/test_keys",
        "//rs/nns/cmc",
        "//rs/nns/common",
        "//rs/nns/constants",
        "//rs/nns/governance/api",
        "//rs/nns/test_utils",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/rust_canisters/dfn_candid",
        "//rs/rust_canisters/on_wire",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/cycles_minting",
        "//rs/types/management_canister_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:num-traits",
        "@crate_index//:serde",
        "@crate_index//:serde_cbor",
        "@crate_index//:slog",
        "@crate_index//:wat",
    ],
)

system_test(
    name = "nns_cycles_minting_multi_app_subnets_test",
    env = NNS_CANISTER_ENV,
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/canister_client",
        "//rs/canister_client/sender",
        "//rs/ledger_suite/icp:icp_ledger",
        "//rs/nervous_system/common/test_keys",
        "//rs/nns/cmc",
        "//rs/nns/constants",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/dfn_candid",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/cycles_minting",
        "//rs/types/management_canister_types",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:serde",
        "@crate_index//:serde_cbor",
        "@crate_index//:slog",
        "@crate_index//:wat",
    ],
)

system_test(
    name = "node_removal_from_registry_test",
    env = NNS_CANISTER_ENV,
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/nns/constants",
        "//rs/nns/governance/api",
        "//rs/registry/canister",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/base_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test(
    name = "bitcoin_set_config_proposal_test",
    env = dict(NNS_CANISTER_ENV.items() + {
        "BTC_WASM_PATH": "$(rootpath @btc_canister//file)",
    }.items()),
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + ["@btc_canister//file"],
    deps = [
        # Keep sorted.
        "//rs/config",
        "//rs/nns/constants",
        "//rs/nns/governance/api",
        "//rs/nns/test_utils",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/tests/ckbtc",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:ic-agent",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:libflate",
        "@crate_index//:reqwest",
        "@crate_index//:slog",
    ],
)

system_test(
    name = "certified_registry_test",
    env = NNS_CANISTER_ENV | UNIVERSAL_CANISTER_ENV,
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/crypto/utils/threshold_sig_der",
        "//rs/nns/constants",
        "//rs/nns/test_utils",
        "//rs/registry/canister",
        "//rs/registry/nns_data_provider",
        "//rs/registry/subnet_type",
        "//rs/registry/transport",
        "//rs/rust_canisters/canister_test",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:axum",
        "@crate_index//:prost",
        "@crate_index//:reqwest",
        "@crate_index//:slog",
        "@crate_index//:tokio",
        "@crate_index//:url",
    ],
)

system_test(
    name = "rent_subnet_test",
    env = NNS_CANISTER_ENV | UNIVERSAL_CANISTER_ENV | {
        # Keep sorted.
        "SUBNET_RENTAL_CANISTER_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
        "XRC_MOCK_WASM_PATH": "$(rootpath //rs/rust_canisters/xrc_mock:xrc_mock_canister)",
    },
    tags = [
        "long_test",  # The test takes over 10 minutes so let's not run it on PRs by default.
    ],
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS + [
        # Keep sorted.
        "//rs/rust_canisters/xrc_mock:xrc_mock_canister",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//packages/icrc-ledger-types",
        "//rs/canister_client",
        "//rs/ledger_suite/common/ledger_core",
        "//rs/ledger_suite/icp:icp_ledger",
        "//rs/nervous_system/common",
        "//rs/nervous_system/common/test_keys",
        "//rs/nns/cmc",
        "//rs/nns/constants",
        "//rs/nns/test_utils",
        "//rs/registry/canister",
        "//rs/registry/nns_data_provider",
        "//rs/registry/subnet_features",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/rust_canisters/dfn_candid",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/base_types",
        "//rs/types/types",
        "//rs/universal_canister/lib",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:ic-agent",
        "@crate_index//:ic-utils",
        "@crate_index//:lazy_static",
        "@crate_index//:slog",
        "@crate_index//:url",
    ],
)

system_test(
    name = "node_swap_test",
    env = NNS_CANISTER_ENV | UNIVERSAL_CANISTER_ENV | {
        "IC_ADMIN_PATH": "$(rootpath //rs/registry/admin:ic-admin)",
    },
    tags = [],
    runtime_deps = NNS_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS + [
        "//rs/registry/admin:ic-admin",
    ],
    deps = [
        # Keep sorted.
        "//rs/nervous_system/common",
        "//rs/nervous_system/common/test_keys",
        "//rs/nns/constants",
        "//rs/nns/test_utils",
        "//rs/registry/canister",
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/base_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:reqwest",
        "@crate_index//:slog",
        "@crate_index//:tokio",
    ],
)
